package com.lastproject.ejb.entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity
@NamedQuery(name="Borrowed.findAll", query="SELECT b FROM Borrowed b")
public class Borrowed implements Serializable{
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="id")
	private int id;
	
	@ManyToOne
	@JoinColumn(name="idUser")
	private User user;
	
	@ManyToOne
	@JoinColumn(name="idBook")
	private Book book;
	
	@Temporal(TemporalType.DATE)
	private Date borrowDate;
	
	@Temporal(TemporalType.DATE)
	private Date mustReturnDate;
	
	@Temporal(TemporalType.DATE)
	private Date returnDate;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	public Date getBorrowDate() {
		return borrowDate;
	}

	public void setBorrowDate(Date borrowDate) {
		this.borrowDate = borrowDate;
	}

	public Date getMustReturnDate() {
		return mustReturnDate;
	}

	public void setMustReturnDate(Date mustReturnDate) {
		this.mustReturnDate = mustReturnDate;
	}

	public Date getReturnDate() {
		return returnDate;
	}

	public void setReturnDate(Date returnDate) {
		this.returnDate = returnDate;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((borrowDate == null) ? 0 : borrowDate.hashCode());
		result = prime * result + id;
		result = prime * result
				+ ((mustReturnDate == null) ? 0 : mustReturnDate.hashCode());
		result = prime * result
				+ ((returnDate == null) ? 0 : returnDate.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Borrowed other = (Borrowed) obj;
		if (borrowDate == null) {
			if (other.borrowDate != null)
				return false;
		} else if (!borrowDate.equals(other.borrowDate))
			return false;
		if (id != other.id)
			return false;
		if (mustReturnDate == null) {
			if (other.mustReturnDate != null)
				return false;
		} else if (!mustReturnDate.equals(other.mustReturnDate))
			return false;
		if (returnDate == null) {
			if (other.returnDate != null)
				return false;
		} else if (!returnDate.equals(other.returnDate))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Borrowed [id=" + id + ", borrowDate=" + borrowDate
				+ ", mustReturnDate=" + mustReturnDate + ", returnDate="
				+ returnDate + "]";
	}
	
	

	
	
}
